﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ArbolandiaBL;
public partial class Admin_AdminMasterPage : System.Web.UI.MasterPage
{
    protected void Page_PreLoad(object sender, EventArgs e)
    {
        if (!ArbolandiaBL.Security.ValidLogin())
        {
            Response.Redirect("Logout.aspx");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        InitPage();
    }

    protected void InitPage()
    {
        Initialization.SetTheme();
        var session = (ObSession)Session["ObSession"];
        btnSiteHeaderUserProfile.Text = session.UserName;
        DisableButtons(session.ProfileType);
        ResourceManagerSite.AddScript("Ext.net.DirectEvent.timeout = 3600000;");

        //Load Buttons Menu
        btnCategorys.Menu.Add(Menu.LoadMenuCategorys("Categorys", Constants.MAIN_PANEL, "Cargando Catalogo"));
        btnOrders.Menu.Add(Menu.LoadMenuOrders("Administrador", Constants.MAIN_PANEL, "Cargando Catalogo"));
        btnProducts.Menu.Add(Menu.LoadMenuProducts("Products", Constants.MAIN_PANEL, "Cargando Catalogo"));
        btnSubCategory.Menu.Add(Menu.LoadMenuSubCategory("SubCategory", Constants.MAIN_PANEL, "Cargando Catalogo"));
        //btnSecutiryCatalog.Menu.Add(Menu.LoadMenuSecurityCatalog("Security", Constants.MAIN_PANEL, "Cargando Catalogo"));
        btnPreferences.Menu.Add(Menu.LoadMenuPreferencesCatalog("Preferences", Constants.MAIN_PANEL, "Cargando Catalogo"));
        btnBanners.Menu.Add(Menu.LoadMenuBannersCatalog("Banners", Constants.MAIN_PANEL, "Cargando Catalogo"));
        btnColors.Menu.Add(Menu.LoadMenuColorsCatalog("Colores", Constants.MAIN_PANEL, "Cargando Catalogo"));

        btnSiteHeaderLogout.DirectEvents.Click.Url = "Logout.aspx";
        btnSiteHeaderLogout.DirectEvents.Click.Before = "Ext.getBody().mask('Saliendo del Sistema', 'x-mask-loading');";
    }
    protected void DisableButtons(ProfileType pt)
    {
        try
        {
            if (pt == ProfileType.Almacen)
            {
                btnProducts.Disabled = false;
                btnPreferences.Disabled = false;
                btnColors.Disabled = false;
            }
            else if (pt == ProfileType.Pedidos)
            {
                btnOrders.Disabled = false;
            }
            else if (pt == ProfileType.Admin)
            {
                btnCategorys.Disabled = false;
                btnOrders.Disabled = false;
                btnProducts.Disabled = false;
                btnSubCategory.Disabled = false;
                //btnSecutiryCatalog.Disabled = false;
                btnBanners.Disabled = false;
                btnPreferences.Disabled = false;
                btnColors.Disabled = false;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
}

